home *** CD-ROM | disk | FTP | other *** search
/ Ahoy 1988 September / Ahoy_Magazine_88-09_1988_Double_L.d64 / double sort (.txt) < prev    next >
Commodore BASIC  |  2022-10-26  |  882b  |  25 lines

  1. 0 print"[147]             double sort":print
  2. 1 rem =================================
  3. 2 rem    commodares problem #51-2 :
  4. 3 rem       double sort
  5. 4 rem    solution by
  6. 5 rem       jim speers
  7. 6 rem =================================
  8. 100 dim w$(20),s$(20)
  9. 110 n=n+1: if n>20 then n=n-1: goto 140
  10. 120 input"enter word";w$(n): if w$(n)="^" then n=n-1: goto 140
  11. 130 goto 110
  12. 140 for i=1 to n: s$(i)=w$(i): next
  13. 150 for i=1 to n: x$=w$(i): l=len(x$): if l=1 then 200
  14. 160 for j=1 to l-1: for k=j to l
  15. 170 if mid$(x$,j,1)<mid$(x$,k,1) then 190
  16. 180 t$=mid$(x$,j,1): mid$(x$,j,1)=mid$(x$,k,1): mid$(x$,k,1)=t$
  17. 190 next k,j: w$(i)=x$
  18. 200 next i: for i=1 to n-1: for j=i+1 to n
  19. 210 if len(w$(i))<=len(w$(j)) then 230
  20. 220 t$=w$(i): w$(i)=w$(j): w$(j)=t$: t$=s$(i): s$(i)=s$(j): s$(j)=t$
  21. 230 next j,i: for i=1 to n-1: for j=i+1 to n
  22. 240 if (w$(i)<w$(j)) or (len(w$(i))<>len(w$(j))) then 260
  23. 250 t$=w$(i): w$(i)=w$(j): w$(j)=t$: t$=s$(i): s$(i)=s$(j): s$(j)=t$
  24. 260 next j,i: print"[147]": for i=1 to n: print w$(i)tab(18)s$(i): next
  25.